package com.hkw.utils;

import com.hkw.model.ClassRoom;
import org.apache.commons.dbutils.ResultSetHandler;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * ResultSetHandler的实现类，将查询到的结果集封装成List<ClassRoom>集合
 */
public class ArrayClassRoomHandler implements ResultSetHandler<List<ClassRoom>> {
    List<ClassRoom> list = new ArrayList<>();
    @Override
    public List<ClassRoom> handle(ResultSet resultSet) throws SQLException {
        while(resultSet.next()) {
            ClassRoom classRoom = new ClassRoom();
            classRoom.setId(resultSet.getInt("id"));
            classRoom.setClassTeaName(resultSet.getString("classTeaName"));
            classRoom.setGrade(resultSet.getString("grade"));
            classRoom.setName(resultSet.getString("name"));
            classRoom.setNumber(resultSet.getInt("number"));
            classRoom.setSlogan(resultSet.getString("slogan"));
            list.add(classRoom);
        }
        return list;
    }
}
